#include "cmddbupdatedata.h"
#include "dbctrl.h"
#include "commclassdb.h"

CT_REGISTER_ASYNCCMD(ID_MAINDB_UPDATEDATA, CCmdDBUpdateData);

unsigned int CCmdDBUpdateData::m_uiNowSwapCount = 0;

int CCmdDBUpdateData::Do(void *pData)
{
    int iRet = 0;

    if (!pData)
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    //解析请求
    CCmdDoParam* pstParam = (CCmdDoParam*) pData;
    if (pstParam->m_pMain == NULL ||
        pstParam->m_pstMsgHead->shMsgID != ID_MAINDB_UPDATEDATA ||
        pstParam->m_pstMsgHead->shMsgType != CTLib::EMT_REQUEST)
    {
        CT_ERROR(("Cmd Stat Err Cmd=%d CmdID=%d Tpye=%d",
            ID_MAINDB_UPDATEDATA,
            pstParam->m_pstMsgHead->shMsgID,
            pstParam->m_pstMsgHead->shMsgType));
        return Done(RET_SYS_ERROR);
    }

    m_stHead = *pstParam->m_pstHead;
    m_stMsgHead = *pstParam->m_pstMsgHead;
    m_pstDB = (CDBCtrl*)pstParam->m_pMain;

    iRet = CodeConvert(*pstParam->m_pstCode, m_stReq, NULL, bin_decode());
    //CT_CHECK_BIN_DECODE(pstParam->m_pstCode,m_stReq.iDataLen);
    if (iRet != 0)
    {
        CT_WARNING((""));
        return Done(RET_SYS_ERROR);
    }

    m_stReq.pszData = pstParam->m_pstCode->m_pszBuf + pstParam->m_pstCode->m_ushPos ;

    //mainsvr进行了重新启动
    if(m_stReq.m_uiSwapCount == 0 || m_stReq.m_uiSwapCount == 1)
    {
        m_uiNowSwapCount = 0;
    }
    
    //检查是否接受更新命令
    if(m_stReq.m_uiSwapCount >= m_uiNowSwapCount) 
    {
        if(m_stReq.m_uiSwapCount > m_uiNowSwapCount) //此处表示前端进行了swap update mgr操作，需要检查dbsvr的update mgr是否需要切换
        {
            time_t iNowTime = time(NULL);
            bool bIsSwap = false;
            m_pstDB->m_stUpdateMgr.CheckSwap(10,iNowTime,50,&bIsSwap);
            if (bIsSwap)
            {
                CT_UPDATE(("--------------------swap--------------------"));
            }
        }
        
        CT_TRACE(("UPDATE_DATA: add element string id %s int64 %llu datatype %d optype %d swapTime %d nowswapTime %d dataLen %d",
            m_stReq.m_stKey.m_sStrID.Get(),
            m_stReq.m_stKey.m_u64ID,m_stReq.m_stKey.m_chDataType,m_stReq.m_iOpType,
            m_stReq.m_uiSwapCount,m_uiNowSwapCount,m_stReq.iDataLen));

        /*
        CVarObjectHead stNowHead;
        iRet = m_pstDB->m_stUpdateMgr.GetDataHead(m_stReq.m_stKey, stNowHead);
        if (iRet == RET_OK)
        {
            switch(stNowHead.m_iDataInfo)
            {
            case VOP_CREATE:
                {
                    switch(m_stReq.m_iOpType)
                    {
                    case VOP_CREATE:
                        m_stReq.m_iOpType = VOP_CREATE;
                        break;
                    case VOP_UPDATE:
                        m_stReq.m_iOpType = VOP_CREATE;
                        break;
                    case VOP_DELETE:
                        m_pstDB->m_stUpdateMgr.DeleteData(m_stReq.m_stKey);
                        m_stAns.m_stKey  = m_stReq.m_stKey;
                        return AnsClients(RET_OK);
                    default:
                        break;
                    }
                }
                break;
            case VOP_UPDATE:
                {
                    switch(m_stReq.m_iOpType)
                    {
                    case VOP_CREATE:
                        m_stReq.m_iOpType = VOP_UPDATE;
                        break;
                    case VOP_UPDATE:
                        m_stReq.m_iOpType = VOP_UPDATE;
                        break;
                    case VOP_DELETE:
                        m_stReq.m_iOpType = VOP_DELETE;
                        break;
                    default:
                        break;
                    }
                }
                break;
            case VOP_DELETE:
                {
                    switch(m_stReq.m_iOpType)
                    {
                    case VOP_CREATE:
                        m_stReq.m_iOpType = VOP_UPDATE;
                        break;
                    case VOP_UPDATE:
                        m_stReq.m_iOpType = VOP_UPDATE;
                        break;
                    case VOP_DELETE:
                        m_stReq.m_iOpType = VOP_DELETE;
                        break;
                    default:
                        break;
                    }
                }
                break;
            }
        }
        */

        CVarObjectHead stHead;
        stHead.m_iDataInfo = m_stReq.m_iOpType;
        stHead.m_iDataLen = m_stReq.iDataLen;

        iRet = CheckDataValid(m_stReq.m_iOpType, m_stReq.m_stKey.m_chDataType, m_stReq.iDataLen, m_stReq.pszData);
        if (iRet != 0)
        {
            CT_ERROR(("CheckDataValid error, opt = %d, datelen = %d, data = %p, ret = %d",
                m_stReq.m_iOpType, m_stReq.iDataLen, m_stReq.pszData, iRet));
            return AnsClients(RET_SYS_ERROR);
        }

        //
        if(m_stReq.m_uiSwapCount == m_uiNowSwapCount)
        {
            iRet = m_pstDB->m_stUpdateMgr.UpdateData(m_stReq.m_stKey,m_stReq.pszData,stHead);
            if(iRet == 0)
            {
                CT_UPDATE(("+,%d,%d,%d,%s,%d", 
                    m_stReq.m_stKey.m_chDataType, CT_UINT64_HIGH(m_stReq.m_stKey.m_u64ID), CT_UINT64_LOW(m_stReq.m_stKey.m_u64ID), 
                    m_stReq.m_stKey.m_sStrID(), m_stReq.m_iOpType));
            }
            //mainsvr的当前桶放不进去，出现严重错误
            else
            {
                CT_ERROR(("update data error +,%d,%d,%d,%s,%d",
                    m_stReq.m_stKey.m_chDataType, CT_UINT64_HIGH(m_stReq.m_stKey.m_u64ID), CT_UINT64_LOW(m_stReq.m_stKey.m_u64ID), 
                    m_stReq.m_stKey.m_sStrID(), m_stReq.m_iOpType));
            }
        }
        else
        {
            //保证main的一个桶的数据都能放进去
            if(!m_pstDB->m_stUpdateMgr.CheckPassUsedPentage(80))
            {
                iRet = m_pstDB->m_stUpdateMgr.UpdateData(m_stReq.m_stKey,m_stReq.pszData,stHead);
                if(iRet == 0)
                {
                    //重新记录main的交换次数
                    m_uiNowSwapCount = m_stReq.m_uiSwapCount;
                    CT_UPDATE(("+,%d,%d,%d,%s,%d", 
                        m_stReq.m_stKey.m_chDataType, CT_UINT64_HIGH(m_stReq.m_stKey.m_u64ID), CT_UINT64_LOW(m_stReq.m_stKey.m_u64ID), 
                        m_stReq.m_stKey.m_sStrID(), m_stReq.m_iOpType));
                }
                else
                {
                    CT_ERROR(("update data error +,%d,%d,%d,%s,%d",
                        m_stReq.m_stKey.m_chDataType, CT_UINT64_HIGH(m_stReq.m_stKey.m_u64ID), CT_UINT64_LOW(m_stReq.m_stKey.m_u64ID), 
                        m_stReq.m_stKey.m_sStrID(), m_stReq.m_iOpType));
                }
                
            }
            else
            {
                CT_ERROR(("db data is full"));
                return AnsClients(RET_SYSTEM_FAIL);

            }
        }
    }
    else
    {      
        CT_WARNING(("data package too old"));
        return AnsClients(RET_SYSTEM_FAIL);
    }

    if (iRet)
    {
        CT_WARNING(("add element failed"));
        return AnsClients(RET_SYSTEM_FAIL);
    }

    m_stAns.m_stKey  = m_stReq.m_stKey;
    return AnsClients(iRet);
}


int CCmdDBUpdateData::AnsClients(int iRet)
{
    m_stMsgHead.shMsgType = CTLib::EMT_ANSWER;

    m_stAns.stResult.iResultID = iRet;

    CTCodeStream s(m_pstDB->m_stEncodeBuf);
    CodeConvert(s, m_stMsgHead, NULL, CTLib::bin_encode());
    CodeConvert(s, m_stAns, NULL, CTLib::bin_encode());
    if (s.m_iRet != 0)
    {
        CT_WARNING((""));
        return Done(-1);
    }

    //返回结果
    if (m_pstDB->AnswerToClient(m_stHead, s) != 0)
    {
        CT_WARNING((""));
        return Done(-1);
    }

    CT_TRACE((""));
    return Done(iRet);
}

int CCmdDBUpdateData::CheckDataValid(int iOpType, char cDataType, int iDataLen, char* pszData)
{
    int iRet = 0;
    if (iOpType != VOP_CREATE && iOpType != VOP_UPDATE && iOpType != VOP_DELETE)
    {
        CT_ERROR(("check data error data type %d optype %d data len %d",cDataType,iOpType,iDataLen));
        return -1;
    }

    if (iDataLen == 0)
    {
        if (pszData != NULL)
        {
            CT_ERROR(("check data error data is null data type %d optype %d data len %d",cDataType,iOpType,iDataLen));
            return -2;
        }

        if (VOP_DELETE != iOpType)
        {
            CT_ERROR(("check data error data type %d optype %d data len %d",cDataType,iOpType,iDataLen));
            return -3;
        }

        return 0;
    }

    if (pszData == NULL)
    {
        if (iDataLen != 0)
        {
            CT_ERROR(("check data error data type %d optype %d data len %d",cDataType,iOpType,iDataLen));
            return -4;
        }

        if (VOP_DELETE != iOpType)
        {
            CT_ERROR(("check data error data type %d optype %d data len %d",cDataType,iOpType,iDataLen));
            return -5;
        }

        return 0;
    }

    CReqSQL stSqlReq;
    CTCodeStream();
    switch (cDataType)
    {
    case DT_PLAYER_BASE_INFO:
        iRet = GetPlayerBaseInfoSqlReq(stSqlReq);
        break;
    case DT_PLAYER_DETAIL_INFO:
        iRet = GetPlayerDetailInfoSqlReq(stSqlReq);
        break;
    case DT_PLAYER_DETAIL_EX1_INFO:
        iRet = GetPlayerDetailInfoEx1SqlReq(stSqlReq);
        break;
    case DT_PLAYER_SNS_DETAIL_INFO:
        iRet = GetPlayerSnsDetailInfoSqlReq(stSqlReq);
        break;
    case DT_PLAYER_UNACT_PARTNER:
        iRet = GetUnactPartnerInfoSqlReq(stSqlReq);
        break;
    case DT_ARENA_RANK:
        iRet = GetArenaRankSqlReq(stSqlReq);
        break;
    case DT_ZONE_DATA:
        iRet = GetZoneDataSqlReq(stSqlReq);
        break;
    case DT_CLAN_DATA:
        iRet = GetClanDataSqlReq(stSqlReq);
        break;
    case DT_OSS_PLAYER_DATA:
        iRet = GetOssPlayerDataSqlReq(stSqlReq);
        break;
    case DT_OSS_ZONE_DATA:
        iRet = GetOssZoneDataSqlReq(stSqlReq);
        break;
    case DT_INSTANCE_ZONE_DETAIL_INFO:
        iRet = GetInstanceZoneDetailInfoSqlReq(stSqlReq);
        break;
    case DT_OSS_PLAYER_MONEY:
        iRet = GetOssPlayerMoneySql(stSqlReq);
        break;

    default :
        CT_WARNING(("CheckDataValid error , invalid data type %d",cDataType));
        return -1;
    }

    if (iRet != 0)
    {
        return iRet;
    }

    return 0;
}

int CCmdDBUpdateData::GetPlayerBaseInfoSqlReq(CReqSQL& stReq)
{
    CPlayerBaseInfo stPlayerBaseInfo;
    int iRet = 0;
    if (m_stReq.m_iOpType !=  VOP_DELETE)
    {
        iRet = CDBCtrl::DataDecode(stPlayerBaseInfo, m_stReq.pszData, m_stReq.iDataLen);
        if(iRet == 0)
        {
            if (m_stReq.m_iOpType == VOP_CREATE)
            {
                iRet = CPlayerBaseInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stPlayerBaseInfo, m_pstDB->m_stEncodeBuf);
            }
            else
            {
                iRet = CPlayerBaseInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stPlayerBaseInfo,
                    m_pstDB->m_stEncodeBuf);
            }
            
            if (iRet != 0)
            {
                CT_ERROR((""));
            }
            else
            {
                CT_TRACE(("update player base info key %u", stPlayerBaseInfo._uiGID));
            }
        }
        else
        {
            CT_WARNING(("DataDecode CPlayerBaseInfo error %d datalen %d point %d",iRet,
                m_stReq.iDataLen,m_stReq.pszData));
        }
    }
    else
    {
        CT_ERROR(("CPlayerBaseInfoDB do not have delete"));
        iRet = -1;
    }

    return iRet;
}


int CCmdDBUpdateData::GetPlayerDetailInfoSqlReq(CReqSQL& stReq)
{
    CPlayerDetailInfo stPlayerDetailInfo;
    int iRet = 0;
    if (m_stReq.m_iOpType !=  VOP_DELETE)
    {
        iRet = CDBCtrl::DataDecode(stPlayerDetailInfo, m_stReq.pszData, m_stReq.iDataLen);
        if(iRet == 0)
        {
            if (m_stReq.m_iOpType == VOP_CREATE)
            {
                iRet = CPlayerDetailInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stPlayerDetailInfo,
                    m_pstDB->m_stEncodeBuf);
            }
            else
            {
                iRet = CPlayerDetailInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stPlayerDetailInfo,
                    m_pstDB->m_stEncodeBuf);
            }

            if (iRet != 0)
            {
                CT_ERROR((""));
            }
            else
            {
                CT_TRACE(("update player detail info key %u", stPlayerDetailInfo._uiGID));
            }
        }
        else
        {
            CT_WARNING(("DataDecode CPlayerDetailInfo error %d datalen %d point %d",iRet,
                m_stReq.iDataLen, m_stReq.pszData));
        }
    }
    else
    {
        CT_ERROR(("CPlayerDetailInfoDB do not have delete"));
        iRet = -1;
    }

    return iRet;
}

int CCmdDBUpdateData::GetPlayerDetailInfoEx1SqlReq(CReqSQL& stReq)
{
    CPlayerDetailInfoEx1 stPlayerDetailInfoEx1;
    unsigned int uiGID = CT_UINT64_LOW(m_stReq.m_stKey.m_u64ID);

    int iRet = 0;
    if (m_stReq.m_iOpType !=  VOP_DELETE)
    {
        iRet = CDBCtrl::DataDecode(stPlayerDetailInfoEx1, m_stReq.pszData, m_stReq.iDataLen);
        if(iRet == 0)
        {
            if (m_stReq.m_iOpType == VOP_CREATE)
            {
                iRet = CPlayerDetailInfoEx1DB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), uiGID, stPlayerDetailInfoEx1,
                    m_pstDB->m_stEncodeBuf);
            }
            else
            {
                iRet = CPlayerDetailInfoEx1DB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), uiGID, stPlayerDetailInfoEx1,
                    m_pstDB->m_stEncodeBuf);
            }

            if (iRet != 0)
            {
                CT_ERROR((""));
            }
            else
            {
                CT_TRACE(("update player detail ex1 info key %u", uiGID));
            }
        }
        else
        {
            CT_WARNING(("DataDecode CPlayerDetailInfoEx1 error %d datalen %d point %d",iRet,
                m_stReq.iDataLen, m_stReq.pszData));
        }
    }
    else
    {
        CT_ERROR(("CPlayerDetailInfoEx1 do not have delete"));
        iRet = -1;
    }

    return iRet;
}

int CCmdDBUpdateData::GetPlayerSnsDetailInfoSqlReq(CReqSQL& stReq)
{
    CPlayerSnsDetailInfo stPlayerSnsDetailInfo;
    int iRet = 0;
    if (m_stReq.m_iOpType !=  VOP_DELETE)
    {
        iRet = CDBCtrl::DataDecode(stPlayerSnsDetailInfo, m_stReq.pszData, m_stReq.iDataLen);
        if(iRet == 0)
        {
            if (m_stReq.m_iOpType == VOP_CREATE)
            {
                iRet = CPlayerSnsDetailInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stPlayerSnsDetailInfo,
                    m_pstDB->m_stEncodeBuf);
            }
            else
            {
                iRet = CPlayerSnsDetailInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stPlayerSnsDetailInfo,
                    m_pstDB->m_stEncodeBuf);
            }

            if (iRet != 0)
            {
                CT_ERROR((""));
            }
            else
            {
                CT_TRACE(("update player sns detail info key %u", stPlayerSnsDetailInfo._uiGID));
            }
        }
        else
        {
            CT_WARNING(("DataDecode stPlayerSnsDetailInfo error %d datalen %d point %d",iRet,
                m_stReq.iDataLen, m_stReq.pszData));
        }
    }
    else
    {
        CT_ERROR(("CPlayerSnsDetailInfoDB do not have delete"));
        iRet = -1;
    }

    return iRet;
}

int CCmdDBUpdateData::GetUnactPartnerInfoSqlReq(CReqSQL& stReq)
{
    CUnactPartnerInfo stUnactPartnerInfo;
    int iRet = 0;
    if (m_stReq.m_iOpType !=  VOP_DELETE)
    {
        iRet = CDBCtrl::DataDecode(stUnactPartnerInfo, m_stReq.pszData, m_stReq.iDataLen);
        if(iRet == 0)
        {
            if (m_stReq.m_iOpType == VOP_CREATE)
            {
                iRet = CUnactPartnerInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stUnactPartnerInfo,
                    m_pstDB->m_stEncodeBuf);
            }
            else
            {
                iRet = CUnactPartnerInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stUnactPartnerInfo,
                    m_pstDB->m_stEncodeBuf);
            }
            
            if (iRet != 0)
            {
                CT_ERROR((""));
            }
            else
            {
                CT_TRACE(("update unact partner info key %u", stUnactPartnerInfo._uiGID));
            }
        }
        else
        {
            CT_WARNING(("DataDecode stUnactPartnerInfo error %d datalen %d point %d",iRet,
                m_stReq.iDataLen, m_stReq.pszData));
        }
    }
    else
    {
        CT_ERROR(("CUnactPartnerInfoDB do not have delete"));
        iRet = -1;
    }

    return iRet;
}

int CCmdDBUpdateData::GetArenaRankSqlReq(CReqSQL& stReq)
{
    CArenaRank stArenaRank;
    int iRet = 0;
    if (m_stReq.m_iOpType !=  VOP_DELETE)
    {
        iRet = CDBCtrl::DataDecode(stArenaRank, m_stReq.pszData, m_stReq.iDataLen);
        if(iRet == 0)
        {
            if (m_stReq.m_iOpType == VOP_CREATE)
            {
                iRet = CArenaRankDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stArenaRank,
                    m_pstDB->m_stEncodeBuf);
            }
            else
            {
                iRet = CArenaRankDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stArenaRank,
                    m_pstDB->m_stEncodeBuf);
            }

            if (iRet != 0)
            {
                CT_ERROR((""));
            }
            else
            {
                CT_TRACE(("update arena rank key %u", stArenaRank._uiGID));
            }
        }
        else
        {
            CT_WARNING(("DataDecode stArenaRank error %d datalen %d point %d",iRet,
                m_stReq.iDataLen, m_stReq.pszData));
        }
    }
    else
    {
        CT_ERROR(("CArenaRankDB do not have delete"));
        iRet = -1;
    }

    return iRet;
}

int CCmdDBUpdateData::GetZoneDataSqlReq(CReqSQL& stReq)
{
    CZoneData stZoneData;
    int iRet = 0;
    if (m_stReq.m_iOpType !=  VOP_DELETE)
    {
        iRet = CDBCtrl::DataDecode(stZoneData, m_stReq.pszData, m_stReq.iDataLen);
        if(iRet == 0)
        {
            if (m_stReq.m_iOpType == VOP_CREATE)
            {
                iRet = CZoneDataDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stZoneData,
                    m_pstDB->m_stEncodeBuf);
            }
            else
            {
                iRet = CZoneDataDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stZoneData,
                    m_pstDB->m_stEncodeBuf);
            }  

            if (iRet != 0)
            {
                CT_ERROR((""));
            }
            else
            {
                CT_TRACE(("update zone data key %d", stZoneData._uiZoneID));
            }
        }
        else
        {
            CT_WARNING(("DataDecode CZoneData error %d datalen %d point %d",iRet,
                m_stReq.iDataLen, m_stReq.pszData));
        }
    }
    else
    {
        CT_ERROR(("CZoneDataDB do not have delete"));
        iRet = -1;
    }

    return iRet;
}

int CCmdDBUpdateData::GetClanDataSqlReq(CReqSQL& stReq)
{
    CClanData stClanData;
    int iRet = 0;
    
    iRet = CDBCtrl::DataDecode(stClanData, m_stReq.pszData, m_stReq.iDataLen);
    if(iRet == 0)
    {
        if (m_stReq.m_iOpType == VOP_DELETE)
        {
            iRet = CClanDataDB::BuildDeleteSQL(stReq, m_pstDB->m_szDBName.Get(), stClanData._uiClanID);
        }
        else
        {
            iRet = CClanDataDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stClanData,
                m_pstDB->m_stEncodeBuf);
        }  

        if (iRet != 0)
        {
            CT_ERROR(("%d", iRet));
        }
    }
    else
    {
        CT_WARNING(("DataDecode CClanData error %d datalen %d point %d",iRet,
            m_stReq.iDataLen, m_stReq.pszData));
    }

    return iRet;
}

int CCmdDBUpdateData::GetOssPlayerDataSqlReq(CReqSQL& stReq)
{
    CPlayerOssData stPlayerOssData;
    
    int iRet = 0;

    iRet = CDBCtrl::DataDecode(stPlayerOssData, m_stReq.pszData, m_stReq.iDataLen);
    if(iRet == 0)
    {
        iRet = CPlayerOssDataDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stPlayerOssData, m_pstDB->m_stEncodeBuf);
        
        if (iRet != 0)
        {
            CT_ERROR(("%d", iRet));
        }
    }
    else
    {
        CT_WARNING(("DataDecode CPlayerOssData error %d datalen %d point %d",iRet,
            m_stReq.iDataLen, m_stReq.pszData));
    }

    return iRet;
}

int CCmdDBUpdateData::GetOssZoneDataSqlReq(CReqSQL& stReq)
{
    COssZoneData stOssZoneData;

    int iRet = 0;

    iRet = CDBCtrl::DataDecode(stOssZoneData, m_stReq.pszData, m_stReq.iDataLen);
    if(iRet == 0)
    {
        iRet = COssZoneDataDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stOssZoneData, m_pstDB->m_stEncodeBuf);

        if (iRet != 0)
        {
            CT_ERROR(("%d", iRet));
        }
    }
    else
    {
        CT_WARNING(("DataDecode COssZoneData error %d datalen %d point %d",iRet,
            m_stReq.iDataLen, m_stReq.pszData));
    }

    return iRet;
}

int CCmdDBUpdateData::GetInstanceZoneDetailInfoSqlReq(CReqSQL& stReq)
{
    CInstanceZoneDetailInfo stData;

    int iRet = 0;

    iRet = CDBCtrl::DataDecode(stData, m_stReq.pszData, m_stReq.iDataLen);
    if(iRet == 0)
    {
        iRet = CInstanceZoneDetailInfoDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stData, m_pstDB->m_stEncodeBuf);

        if (iRet != 0)
        {
            CT_ERROR(("%d", iRet));
        }
    }
    else
    {
        CT_WARNING(("DataDecode CInstanceZoneDetailInfo error %d datalen %d point %d",iRet,
            m_stReq.iDataLen, m_stReq.pszData));
    }

    return iRet;
}

int CCmdDBUpdateData::GetOssPlayerMoneySql(CReqSQL& stReq)
{
    CPlayerOssMoney stData;

    int iRet = 0;

    iRet = CDBCtrl::DataDecode(stData, m_stReq.pszData, m_stReq.iDataLen);
    if(iRet == 0)
    {
        iRet = CPlayerOssMoneyDB::BuildReplaceSQL(stReq, m_pstDB->m_szDBName.Get(), stData, m_pstDB->m_stEncodeBuf);

        if (iRet != 0)
        {
            CT_ERROR(("%d", iRet));
        }
    }
    else
    {
        CT_WARNING(("DataDecode CPlayerOssMoneyDB error %d datalen %d point %d",iRet,
            m_stReq.iDataLen, m_stReq.pszData));
    }

    return iRet;
}